package com.ask.service.utilService;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Service;

/**
 * Bloom过滤器
 */
@Service
public class BloomFilterService {

    private BloomFilter<Long> bloomFilter;

    @PostConstruct
    public void init() {
        bloomFilter = BloomFilter.create(Funnels.longFunnel(), 1000000, 0.01);
    }

    public void add(Long id) {
        bloomFilter.put(id);
    }

    public boolean mightContain(Long id) {
        return bloomFilter.mightContain(id);
    }
}
